<admintpl file="header"/>
<script>
    document.domain = "xinhuiwen.com";
</script>
</head>
<body>
<div class="wrap">
    <ul class="nav nav-tabs">
        <?php if($special_id){ ?>
        <li><a href="{:U('Admin/Special/index',array('news_id'=>$special_id,$id_type=>$id_val))}">新闻列表</a></li>
        <?php }else{ ?>
        <li><a href="{:U('Admin/News/index',array($id_type=>$id_val))}">新闻列表</a></li>
        <?php } ?>
        <li class="active"><a href="{:U('Admin/NewsManage/pictureAdd',array('special_id'=>$special_id,$id_type=>$id_val))}">添加{$Title}</a></li>
    </ul>


    <?php if($return_val == 0){ ?>
        <iframe src='<?php echo C("cmshost");?>/create/images-news?<?php echo $id_type;?>=<?php echo $id_val;?>&news_id=<?php echo $news_id;?>&special_id=<?php echo $special_id;?>' id="iframepage" name="iframepage" frameBorder="0" width="100%" height="90%" allowfullscreen="true"></iframe>

    <style>
        html, body, .wrap {
            height: 100%;
        }
        .wrap {
            box-sizing: border-box;
        }
    </style>
    <?php }else{ ?>
        <form method="post" class="form-horizontal" id="form.js-ajax-forms"
              action="{:U('Admin/NewsManage/addImage')}" enctype="multipart/form-data">
            <div class="control-group">
                <label class="span1 control-label" style="width: 90px;">新闻标题：</label>
                <div class="span3">
                    <input type="text" name="title"  style="width: 556px;" value="{$news_info.title}">
                </div>
            </div>
            <div class="control-group">
                <label class="span1 control-label" style="width: 90px;">副标：</label>
                <div class="span3">
                    <input type="text" name="subTitle"  style="width: 556px;" value="{$news_info.subtitle}">
                </div>
            </div>
            <div class="control-group">
                <label class="span1 control-label" style="width: 90px;">关键字：</label>
                <div class="span3">
                    <input type="text" name="keyword"  style="width: 556px;" value="{$news_info.keywords}">
                </div>
            </div>
            <div class="control-group">
                <label class="span1 control-label" style="width: 90px;">新闻来源：</label>
                <div class="span3">
                    <input type="text" name="source"  style="width: 556px;" value="{$news_info.source_name}">
                </div>
            </div>
            <div class="control-group">
                <label class="span1 control-label" style="width: 90px;">权重：</label>
                <div class="span3">
                    <input type="text" name="weight"  style="width: 556px;" value="{$news_info.weight}">
                </div>
            </div>
            <div class="control-group">
                <label class="span1 control-label" style="width: 90px;">标签：</label>
                <div class="span3">
                    <input type="text" name="tags"  style="width: 556px;" value="{$news_info.tags}">
                </div>
            </div>
            <div class="control-group">
                <label class="span2 control-label" style="width: 90px;">新闻摘要：</label>
                <div class="span7">
                    <textarea style="width: 556px; height: 60px;" name="abstract">{$news_info.abstract}</textarea>
                </div>
            </div>
            <?php if($type != '2'){?>
            <div class="control-group">
                <label class="span1 control-label" style="width: 90px;">是否置顶：</label>
                <div class="span3">
                    <label class="radio inline" for="lightup_true"> <input type="radio" id="top_status" <if condition="$news_info.top_status eq 1"> checked </if> class="radio" name="top_status" value="1" />是</label> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <label class="radio inline" for="lightup_false"> <input type="radio" id="top_status" <if condition="$news_info.top_status eq 0"> checked </if> class="radio" name="top_status" value="0" />否</label>
                </div>
            </div>
            <?php }?>
            <?php if($type == '2'){?>
            <div class="control-group">
                <label class="span1 control-label" style="width: 90px;">专题分栏：</label>
                <div class="span3">
                    <select class="select_2" name="special_type" id="special_type" >
                        <foreach name="special_column_type_list" item="vo">
                            <option value="{$vo.type_id}" <?php if(isset($type_id)){ if($vo['type_id'] == $type_id) echo "selected";}?> >{$vo.name}</option>
                        </foreach>
                    </select>
                </div>
            </div>
            <?php }else{?>
            <div class="control-group">
                <label class="span1 control-label" style="width: 90px;">栏目类型：</label>
                <div class="span3">
                    <select class="select_2" name="column_type" id="column_type" >
                        <foreach name="type_list" item="vo">
                            <option value="{$vo.type_id}" <?php if($vo['type_id']==$news_info['type_id']) {echo "selected";}?>>
                            {$vo.name}</option>
                        </foreach>
                    </select>
                </div>
            </div>
            <?php } ?>
            <div class="control-group">
                <label class="span2 control-label" style="width: 90px;">新闻正文：</label>
                <div class="span7">
                    <table>
                        <tr>
                            <td style="width: 135px">
                                <div id="imageDiv" class="file-item thumbnail" style="width:150px;height: 150px;">
                                    <?php
                                            if(!empty($news_info['cover_image'])){
                                        ?>
                                    <img id="imageUrl{$count}_preview" src="{$news_info.cover_image}" style="width:150px;height: 140px;">
                                    <?php
                                            }else{
                                            ?>
                                    <img id="imageUrl{$count}_preview" src="__PUBLIC__/images/furley_bg.png" style="width:150px;height: 140px;">
                                    <?php
                                            }
                                            ?>
                                    <div id="picker" class="info" onclick="checkImage('FileImage{$count}');">选择图片&nbsp;&nbsp;&nbsp;&nbsp;</div>
                                    <input style="display:none;" type="file" id="FileImage{$count}" name="imageFile[]" onchange="changeImage(this.id,'imageUrl{$count}_preview','{$count}');">
                                    <input style="display:none;" type="hidden" class="imageUrl{$count}_preview" name="update[]" value="">
                                </div>
                                <!--<div style="text-align: left;">-->
                                <!--<input type="hidden" name="imageUrl[]" id="imageUrl1" value="">-->
                                <!--<a href="javascript:void(0);"-->
                                <!--onclick="flashupload('thumb_images', '附件上传','imageUrl1',thumb_images,'1,jpg|jpeg|gif|png|bmp,1,,,1','','','');return false;">-->
                                <!--<img src="__TMPL__Public/assets/images/default-thumbnail.png" id="imageUrl1_preview"-->
                                <!--width="135" style="cursor: hand"/>-->
                                <!--</a>-->
                                <!--</div>-->
                            </td>
                            <td>
                                <textarea style="width: 380px"  name="pictureDescs{$count}" rows="6" placeholder="图片描述"></textarea>
                            </td>
                            <td style="">
                                <div style="color:red;width:350px;vertical-align:bottom">*前三张图集缩略  尺寸：304*204  格式：JPG/PN</div>
                            </td>
                        </tr>
                    </table>
                </div>
                <div class="span2" style=" vertical-align:bottom">
                    <input type="hidden" value="1" name="pictureCount" id="pictureCount">
                    <input type="hidden" value="{$count}" name="pictureMax" id="pictureMax">
                    <input type="hidden" value="<?php if($news_info['title']){echo 1;}else{echo 0;}?>" name="addOredit" >
                    <a style="font-size: 25px" onclick="copyHtml()">添加+</a>
                </div>
            </div>
            <div class="control-group" id="pictureHtml" style="display:none " >
                <div class="span7" style="margin-left: 130px;">
                    <table>
                        <tr>
                            <td style="width: 135px">
                                <div id="imageDiv" class="file-item thumbnail" style="width:150px;height: 150px;">
                                    <?php
                                            if(!empty($news_info['cover_image'])){
                                        ?>
                                    <img id="imageUrl_preview" src="{$news_info.cover_image}" style="width:150px;height: 140px;">
                                    <?php
                                            }else{
                                            ?>
                                    <img id="imageUrl_preview" src="__PUBLIC__/images/furley_bg.png" style="width:150px;height: 140px;">
                                    <?php
                                            }
                                            ?>
                                    <div id="picker" class="info" onclick="checkImage('FileImage');">选择图片&nbsp;&nbsp;&nbsp;&nbsp;</div>
                                    <input style="display:none;" type="file" id="FileImage" name="imageFiles[]" onchange="changeImage(this.id,'imageUrl_preview','num');">
                                    <input style="display:none;" type="hidden" class="imageUrl_preview" name="update[]" value="">

                                </div>
                                <!--<div style="text-align: left;">-->
                                <!--<input type="hidden" name="imageUrl[]" id="imageCopy" value="">-->
                                <!--<a href="javascript:void(0);"-->
                                <!--onclick="flashupload('thumb_images', '附件上传','imageCopy',thumb_images,'1,jpg|jpeg|gif|png|bmp,1,,,1','','','');return false;">-->
                                <!--<img src="__TMPL__Public/assets/images/default-thumbnail.png" id="imageCopy_preview"-->
                                <!--width="135"-->
                                <!--style="cursor: hand"/>-->
                                <!--</a>-->
                                <!--</div>-->
                            </td>
                            <td>
                                <textarea style="width: 380px" name="pictureDescs" rows="6" placeholder="图片描述"></textarea>
                            </td>
                        </tr>
                    </table>
                </div>
                <div class="span2" style=" vertical-align:bottom">
                    <a style="font-size: 25px" onclick="removeHtml(this)">删除</a>
                </div>
            </div>
            <?php if(!empty($news_info['content'])){
                    $content = json_decode($news_info['content'],true);
                    foreach($content as $key=>$val){

            ?>
            <div class="control-group" id="pictureHtml" >
                <div class="span7" style="margin-left: 130px;">
                    <table>
                        <tr>
                            <td style="width: 135px">
                                <div id="imageDiv" class="file-item thumbnail" style="width:150px;height: 150px;">
                                    <img id="imageUrl_preview{$key+1}" src="{$val.img}" style="width:150px;height: 140px;">
                                    <input type="hidden" name="images[{$key+1}]" value="{$val.img}" id="images{$key+1}">
                                    <div id="picker" class="info" onclick="checkImage('FileImage{$key+1}');">选择图片&nbsp;&nbsp;&nbsp;&nbsp;</div>
                                    <input style="display:none;" type="file" id="FileImage{$key+1}" name="imageFiles[]" onchange="changeImage(this.id,'imageUrl_preview{$key+1}','{$key+1}');">
                                    <input style="display:none;" type="hidden" class="imageUrl_preview{$key+1}" name="update[]" value="">

                                </div>
                            </td>
                            <td>
                                <textarea style="width: 380px" name="pictureDescs{$key+1}" rows="6" placeholder="图片描述" id="desc{$key+1}">{$val.text}</textarea>
                                <input type="hidden" name="desc_{$key+1}" value="{$val.text}">
                            </td>
                        </tr>
                    </table>
                </div>
                <div class="span2" style=" vertical-align:bottom">
                    <a style="font-size: 25px" onclick="removeHtml(this)">删除</a>
                </div>
            </div>
            <?php

                    }
                }?>
            <div class="control-group">
                <label class="span1 control-label" style="width: 90px;">是否添加图片水印：</label>
                <div class="span3">
                    <label class="radio inline" for="lightup_true"> <input type="radio" id="water_true" class="radio" name="water" value="1" <if condition="$news_info.is_watermark eq 1"> checked </if> />开启</label> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <label class="radio inline" for="lightup_false"> <input type="radio" id="water_false"  class="radio" name="water" value="0" <if condition="$news_info.is_watermark eq 0">checked </if> />关闭</label>
                </div>

            </div>
            <div class="control-group">
                <label class="span1 control-label" style="width: 90px;">发布渠道：</label>
                <div class="span3">
                    <label class="radio inline" for="lightup_true"> <input type="checkbox" <if condition="$news_info.app_pub eq 1"> checked </if> id="pub" class="radio" name="pub[]" value="1" />APP</label> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <label class="radio inline" for="lightup_false"> <input type="checkbox" id="pub" <if condition="$news_info.web_pub eq 1"> checked </if>  class="radio" name="pub[]" value="2" />门户</label>
                </div>


            </div>
            <div class="control-group">
                <label class="span1 control-label" style="width: 90px;">内部链接：</label>
                <div class="span3" style="width:556px">
                    <input type="text" name="reference"  style="width: 556px;" value="<?php if($news_info['reference_id'] && $news_info['reference_type']) echo "id=".$news_info['reference_id']."&type=".$news_info['reference_type'];?>">
                </div>
                <?php if($news_info['reference_id'] && $news_info['reference_type']){ ?>
                <div style="float: left; margin-left: 50px;"><a href="<?php echo U('NewsManage/publish', array('news_id'=>$news_info['reference_id']));?>">维护新闻</a></div>
                <?php } ?>
            </div>
            <div class="control-group">
                <label class="span1 control-label" style="width: 90px;">阅读原文：</label>
                <div class="span3">
                    <input type="text" name="outer_url"  style="width: 556px;" value="{$news_info.outer_url}">
                    <label  for="lightup_false"> <input type="checkbox" id="outer_url_pub" <if condition="$news_info.outer_url_ishot eq 1"> checked </if>  class="radio" name="outer_url_pub" value="1" />设为新闻链接</label>
                </div>
            </div>
            <input type="hidden" name="special_id" value="<?php echo isset($special_id) ? $special_id : '0'?>">
            <input type="hidden" name="news_id" value="{$news_info.news_id}">
            <input type="hidden" name="{$id_type}"  value="{$id_val}" style="width: 556px;">
            <input type="hidden" name="type"  value="5" style="width: 556px;">
            <div class="form-actions" style="padding-left:260px;">
                <button type="submit" class="btn btn-primary">保存</button>
                &nbsp;&nbsp;
                <!--<a class="btn" href="{:U('Admin/News/index?'.$id_type.'='.$id_val.'&news_id='.$news_info['news_id'])}">{:L('BACK')}</a>-->

                <if condition="$type eq 2">
                    <a class="btn" href="{:U('Admin/Special/index',array('special_id'=>$special_id,$id_type=>$id_val,'news_id'=>$news_info['news_id']))}">{:L('BACK')}</a>
                    <else/>
                    <a class="btn" href="{:U('Admin/News/index?'.$id_type.'='.$id_val)}">{:L('BACK')}</a>
                </if>

            </div>
        </form>
    <?php } ?>
</div>
    <?php if($return_val == 1){ ?>
        <!--<script src="__PUBLIC__/js/common.js"></script>-->
        <!--<script type="text/javascript" src="__PUBLIC__/js/content_addtop.js"></script>-->
        <script type="text/javascript">
            $(document).ready(function () {
                $('#province').change(function () {
                    $.get('{:U("Admin/News/getCity")}' + '&pid=' + $('#province').val(), function (data) {
                        var html = '<option value="0">--无--</option>';
                        if (data['state'] == "success") {
                            html = '<option value="0">全部</option>';
                            for (var a in data.data) {
                                html += '<option value="' + data.data[a].aId + '">' + data.data[a].aN + '</option>';
                            }
                        }
                        $('#city').html(html);
                    });
                });

                $('#category').change(function () {
                    $.get('{:U("Admin/News/getTags")}' + '&cId=' + $('#category').val(), function (data) {
                        var html = '<option value="0">--无--</option>';
                        if (data['state'] == "success") {
                            html = '<option value="0">全部</option>';
                            for (var a in data.data) {
                                html += '<option value="' + data.data[a].tagId + '">' + data.data[a].tagName + '</option>';
                            }
                        }
                        $('#tags').html(html);
                    });
                });

            });
            function copyHtml(){
                var addHtml=$("#pictureHtml").html();
                var pictureMaxValue=$("#pictureMax").val();
                var newMaxValue=parseInt(pictureMaxValue)+1;
                $("#pictureMax").val(newMaxValue);

                var newImgId="imageUrl"+newMaxValue;
                var pickerId="picker"+newMaxValue;
                var imageUrl="imageUrl"+newMaxValue+"_preview";
                var imageFileId="FileImage"+newMaxValue;
                var image      ="imageFile";
                var des = "pictureDescs"+newMaxValue;
                var add2Html=addHtml.replace(new RegExp("imageCopy","gm"),newImgId);
                add2Html1=add2Html.replace(new RegExp("picker","gm"),pickerId);
                add2Html2=add2Html1.replace(new RegExp("imageUrl_preview","gm"),imageUrl);
                add2Html3=add2Html2.replace(new RegExp("FileImage","gm"),imageFileId);
                add2Html5=add2Html3.replace(new RegExp("imageFiles","gm"),image);
                add2Html6=add2Html5.replace(new RegExp("num","gm"),newMaxValue);
                add2Html7=add2Html6.replace(new RegExp("pictureDescs","gm"),des);
                add2Html4="<div class='control-group' id='pictureHtml"+newMaxValue+"'  >"+add2Html7+"</div>";
                $("#pictureHtml").before(add2Html4);

                var pictureCount=$("#pictureCount").val();
                var newCount=parseInt(pictureCount)+1;
                $("#pictureCount").val(newCount);

            }
            function removeHtml($obj){
                $($obj).parent().parent().remove();
                var pictureCount=$("#pictureCount").val();
                var newCount=parseInt(pictureCount)-1;
                $("#pictureCount").val(newCount);
            }

            function html5Reader(file, previewId){
                var file = file.files[0];
                var reader = new FileReader();
                reader.readAsDataURL(file);
                reader.onload = function(e){
                    $('#'+previewId).attr('src', this.result);
                }
            }
            function image_change(fileId, previewId, num) {
                var pic = document.getElementById(previewId),
                        file = document.getElementById(fileId);

                var ext = file.value.substring(file.value.lastIndexOf(".")+1).toLowerCase();
                $("."+previewId).val(num);
                $("#"+fileId).attr("name",'imageFile[]');
                if(num != ''){
                    $("#images"+num).val('');
                    $("#desc"+num).attr("name", 'pictureDescs'+num);
                    $("#desc_"+num).val('');
                }
                // gif在IE浏览器暂时无法显示
                if(ext != 'png' && ext != 'jpg' && ext != 'jpeg'){
                    alert("图片的格式必须为png或者jpg或者jpeg格式！");
                    return;
                }
                var isIE = navigator.userAgent.match(/MSIE/)!= null,
                        isIE6 = navigator.userAgent.match(/MSIE 6.0/)!= null;
                if(isIE) {
                    file.select();
                    var realLocalPath = document.selection.createRange().text;

                    // IE6浏览器设置img的src为本地路径可以直接显示图片
                    if (isIE6) {
                        pic.src = realLocalPath;
                    }else {
                        // 非IE6版本的IE由于安全问题直接设置img的src无法显示本地图片，但是可以通过滤镜来实现
                        pic.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod='image',src=\"" + realLocalPath + "\")";
                        // 设置img的src为base64编码的透明图片 取消显示浏览器默认图片
                        pic.src = '';
                    }
                }else {
                    html5Reader(file, previewId);
                }
            }

            function checkImage(file){
                $("#"+file).click();
            }

            function changeImage(FileImage1,imageUrl_preview1, num){
                image_change(FileImage1, imageUrl_preview1, num);
            }
            //    $("#FileImage").change(function(){
            //
            //    });
        </script>
    <?php }?>

</body>
</html>